<template>
  <div>
    <div>
      <div class="crumbs">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item>
            <i class="el-icon-lx-cascades"></i> 报到统计
          </el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <div class="container">
        <div class="container-left" style="width: 15%">
          <el-tree
              :data="treeData.data"
              :props="{ children: 'children', label: 'label' }"
              node-key="id"
              @node-click="handleNodeClick"
          />
        </div>
        <div class="container-right">
          <el-tabs type="card" @tab-click="handleClick">
            <el-tab-pane label="已报到">
              <el-table
                  :data="tableData"
                  border
                  class="table"
                  ref="multipleTable"
                  header-cell-class-name="table-header"
              >
                <el-table-column label="序号" type="index" :index="indexMethod"/>
                <el-table-column
                    :show-overflow-tooltip="true"
                    :prop="item.prop"
                    :label="item.label"
                    v-for="item in props"
                    :key="item.prop"
                >
                </el-table-column>
              </el-table>
              <div class="pagination">
                <el-pagination
                    :currentPage="query.pageNum"
                    :page-sizes="[10, 20, 40]"
                    :page-size="query.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="pageTotal"
                    @size-change="handleSizeChange"
                    @current-change="handlePageChange"
                >
                </el-pagination>
              </div>
            </el-tab-pane>
            <el-tab-pane label="未报到">
              <el-table
                  :data="tableFileData"
                  border
                  class="table"
                  ref="multipleTable"
                  header-cell-class-name="table-header"
              >
                <el-table-column label="序号" type="index" :index="indexMethod"/>
                <el-table-column
                    :show-overflow-tooltip="true"
                    :prop="item.prop"
                    :label="item.label"
                    v-for="item in fileProps"
                    :key="item.prop"
                >
                </el-table-column>
                <!--                <el-table-column>-->
                <!--                  <el-table-column-->
                <!--                      label="操作"-->
                <!--                      width="220px"-->
                <!--                      align="center"-->
                <!--                      fixed="right"-->
                <!--                  >-->
                <!--                    <template #default="scope">-->
                <!--                      <el-button-->
                <!--                          type="text"-->
                <!--                          icon="el-icon-delete"-->
                <!--                          class="red"-->
                <!--                          @click="handleGetGoods( scope.row.studentId)"-->
                <!--                      >申领物资-->
                <!--                      </el-button-->
                <!--                      >-->
                <!--                  <el-button-->
                <!--                      type="text"-->
                <!--                      icon="el-icon-edit"-->
                <!--                      class="red"-->
                <!--                      @click="handleAllGoods( scope.$index,scope.row.majorId)"-->
                <!--                  >更多-->
                <!--                  </el-button-->
                <!--                  >-->
                <!--                    </template>-->
                <!--                  </el-table-column>-->
                <!--                </el-table-column>-->
              </el-table>
              <div class="pagination">
                <el-pagination
                    :currentPage="query.pageNum"
                    :page-sizes="[10, 20, 40]"
                    :page-size="query.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="pageTotal"
                    @size-change="handleSizeChange"
                    @current-change="handlePageChange"
                >
                </el-pagination>
              </div>
            </el-tab-pane>
          </el-tabs>


        </div>
      </div>
    </div>
    <!--    <div>-->
    <!--      &lt;!&ndash; 选择物品 &ndash;&gt;-->
    <!--      <el-dialog-->
    <!--          title="物品选择"-->
    <!--          v-model="dialogVisible"-->
    <!--          width="55%"-->
    <!--          :before-close="handleClose"-->
    <!--      >-->
    <!--        <div>-->
    <!--          <el-table-->
    <!--              :data="tableReceiveeData"-->
    <!--              border-->
    <!--              class="table"-->
    <!--              ref="multipleTable"-->
    <!--              header-cell-class-name="table-header"-->
    <!--              @selection-change="handleSelectionChange"-->
    <!--              @row-click="clickRow"-->
    <!--          >-->
    <!--            &lt;!&ndash;          <el-table-column label="序号" type="index" :index="indexMethod" />&ndash;&gt;-->
    <!--            <el-table-column type="selection"/>-->
    <!--            <el-table-column-->
    <!--                :show-overflow-tooltip="true"-->
    <!--                :prop="item.prop"-->
    <!--                :label="item.label"-->
    <!--                v-for="item in propt"-->
    <!--                :key="item.prop"-->
    <!--                align="center"-->
    <!--            >-->
    <!--            </el-table-column>-->
    <!--            <el-table-column label="物品样例" align="center">-->
    <!--              <template #default="scope">-->
    <!--                <p v-if="scope.row.goodsUrl!=null">-->
    <!--                       <span v-for="(item,index) in scope.row.goodsUrl.split(',')" :key="index">-->
    <!--                     <el-image style="display: inline-flex;padding: 10px;width: 30%;height: 10%"-->
    <!--                               class="table-td-thumb"-->
    <!--                               :src="item"-->
    <!--                               :preview-src-list="[item]"-->
    <!--                     ></el-image>-->
    <!--              </span>-->
    <!--                </p>-->
    <!--              </template>-->
    <!--            </el-table-column>-->
    <!--          </el-table>-->

    <!--        </div>-->
    <!--        <el-divider/>-->
    <!--        <template #footer>-->
    <!--            <span class="dialog-footer">-->
    <!--              <el-button @click="dialogVisible = false">关闭</el-button>-->
    <!--               <el-button @click="checkReceive">选取</el-button>-->
    <!--            </span>-->
    <!--        </template>-->
    <!--      </el-dialog>-->
    <!--    </div>-->
  </div>
</template>


<script setup>
import {ElMessage, ElMessageBox} from "element-plus";
import {reactive, ref} from "vue";
import {useRouter} from "vue-router";
import request from "../../utils/request";

const router = useRouter();
const props = [
  {label: "学生姓名", prop: "studentName"},
  {label: "所属专业", prop: "majorName"},
  {label: "所属班级", prop: "className"},
  {label: "学号", prop: "studentId"},
  {label: "到站地点", prop: "address"},
  {label: "预约报到时间", prop: "reserveTime"},
  {label: "乘车方式", prop: "traffic"},
  {label: "车次", prop: "trainNumber"},
  {label: "联系电话", prop: "mobilePhone"},
  {label: "实际报到时间", prop: "realTime"},
  // {label: "当前报到状态", prop: "status"},
];
const fileProps = [
  {label: "学号", prop: "studentId"},
  {label: "学生姓名", prop: "studentName"},
  {label: "身份证号", prop: "idCardNo"},
  {label: "籍贯（省）", prop: "domicilePlaceProvince"},
  {label: "性别", prop: "gender"},
  {label: "民族", prop: "nation"},
  // {label: "年级", prop: "grade"},
  {label: "学院名称", prop: "collegeName"},
  {label: "专业名", prop: "majorName"},
  {label: "班级名称", prop: "className"},
  // { label: "加入班级时间", prop: "allocateDate" },
  // {label: "班级序号", prop: "classCode"},
];

const treeData = reactive({
  data: [],
});
// const queryAdviserId = reactive({
//   adviserId: ""
// })
// request.get("/college/ThreeTree",
//     {
//       params: queryAdviserId,
//     }).then((res) => {
//   treeData.data = res.data;
// });
request.get("/college/ThreeTree").then((res) => {
  treeData.data = res.data;
});
const tableTex = ref(null);
const query = reactive({
  id: "",
  status: "3",
  studentId: "",
  pageNum: 1,
  pageSize: 10,
});
//左右数据选取
const handleClick = (tab) => {
  if (tab.props.label === "已报到") {
    tableTex.value = "已报到";
    getData()
  } else {
    tableTex.value = "未报到";
    getFileData()
  }
};
const tableData = ref([]);
const tableFileData = ref([]);
const pageTotal = ref(0);
// 获取表格数据
//已经报到
const getData = () => {
  query.adviserId = localStorage.getItem("sid")
  request
      .get("/reserve/queryReserveVoAll", {
        params: query,
      })
      .then((res) => {
        if (res.code != "0") {
          ElMessage.warning(res.msg);
          tableData.value = [];
        } else {
          tableData.value = res.data.records;
          for (var i = 0; i < tableData.value.length; i++) {
            if (tableData.value[i].status == 0) {
              tableData.value[i].status = "驳回";
            } else if (tableData.value[i].status == 1) {
              tableData.value[i].status = "待报到";
            } else if (tableData.value[i].status == 2) {
              tableData.value[i].status = "已审核";
            } else if (tableData.value[i].status == 3) {
              tableData.value[i].status = "已报到";
            }
          }
          pageTotal.value = res.data.total;
        }
      });
};
getData();
const getFileData = () => {
  tableFileData.value = [];
  request
      .get("/student/queryfileCheckInAll", {
        params: query,
      })
      .then((res) => {
        if (res.code != 0) {
          ElMessage.warning(res.msg);
          tableFileData.value = [];
        } else {
          tableFileData.value = res.data.records;
          pageTotal.value = res.data.total;
        }
      });
};

//树状触发事件
const handleNodeClick = (data) => {
  console.log(tableTex.value)
  // if (!data.children) {
  query.id = data.id;
  if (tableTex.value === "未报到") {
    getFileData()
  } else {
    getData();
  }

  // }
};
// 查询操作
const handleSearch = () => {
  query.pageNum = 1;
  getData();
};
// 分页大小
const handleSizeChange = (val) => {
  query.pageSize = val;
  getData();
};
// 分页导航
const handlePageChange = (val) => {
  query.pageNum = val;
  getData();
};

//
// const handleGetGoods = (studentId) => {
//   dialogVisible.value = true;
//   console.log(studentId)
//   tableSelection.studentId = studentId
//   // getReceiveData();
// };

//学院下拉框
// const options = ref([]);
// const getAllCollege = () => {
//   console.log(query.collegeId);
//   request.get("/college/getAllCollege").then((res) => {
//     options.value = res.data;
//     getMajor();
//   });
// };
//专业下拉框

// const optionsMajors = ref([]);
// const getMajor = () => {
//   request
//       .get("/major/queryList", {
//         params: {collegeId: query.collegeId, type: 1},
//       })
//       .then((res) => {
//         optionsMajors.value = res.data;
//       });
// };
//班级下拉框
// const classList = ref([]);
// const getClassList = () => {
//   request
//       .get("/class/byMajorIdOrCollegeId", {
//         params: {majorId: query.majorId},
//       })
//       .then((res) => {
//         classList.value = res.data;
//       });
// };
// 新增操作
// const handleAdd = () => {
//   router.push("/admin/addNew");
// };
//
// const handleEdit = (sid) => {
//   router.push({path: "/admin/addNew", query: {id: sid}});
// };


//移除学生
// const handleAlloc = () => {
//
// };
// const dialogVisible = ref(false);


//多选
// const tableSelection = reactive({
//   idList: [],
//   studentId: "",
// });
//选择列表框
// const handleSelectionChange = (val) => {
//   tableSelection.idList = [];
//   for (var i in val) {
//     tableSelection.idList.push(val[i].sid);
//   }
// };
// const checkReceive = () => {
//   console.log(tableSelection)
//   if (tableSelection.idList.length === 0) {
//     ElMessage.info("请选择物品");
//     return;
//   }
//   ElMessageBox.confirm("确定选择物品吗？", "提示", {
//     type: "warning",
//   }).then(() => {
//         request
//             .post("/receive/insertReceives", tableSelection)
//             .then((res) => {
//               if (res.code === null) {
//                 ElMessage.success("成功");
//                 dialogVisible.value = false;
//                 getData();
//               } else {
//                 tableSelection.idList = [];
//                 ElMessage.error(res.msg);
//               }
//             });
//       }
//   );
// };
const indexMethod = (index, number) => {
  return (index + 1)
}
</script>

<style scoped>
.container {
  display: flex;
  flex-direction: row;
}

.container-left {
  width: 20%;
  padding-right: 20px;
}

.container-right {
  width: 80%;
  display: flex;
  flex-direction: column;
}

.btn {
  display: flex;
  text-align: left;
  padding-bottom: 10px;
}

.handle-box {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
}

.handle-select {
  width: 120px;
}

.handle-input {
  width: 300px;
  display: inline-block;
}

.table {
  width: 100%;
  font-size: 14px;
}

.red {
  color: #ff0000;
}

.mr10 {
  margin-right: 10px;
}

.table-td-thumb {
  display: block;
  margin: auto;
  width: 40px;
  height: 40px;
}
</style>